package com.it.travel.controller;

import com.github.pagehelper.PageHelper;
import com.it.travel.service.RouteService;
import com.it.travel.service.UserService;
import com.it.travel.vo.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("route")
public class RouteController {

    @Autowired
    private RouteService routeService;

    /**
     * 精选人气，最新，主题
     * @return
     */
    @RequestMapping("routeCareChoose")
    @ResponseBody
    public ResultInfo routeCareChoose() {
        return routeService.routeCareChoose();
    }

    /**
     * 搜索实现
     * @param cid
     * @param rname
     * @param curPage
     * @return
     */
    @RequestMapping("findRouteList")
    @ResponseBody
    public ResultInfo findRouteList(Integer cid, String rname, @RequestParam(required = false, defaultValue = "1") Integer curPage) {
        return routeService.findRouteList(cid,rname,curPage);
    }

    /**
     * 查看详情
     * @param rid
     * @return
     */
    @RequestMapping("findRouteByRid")
    @ResponseBody
    public ResultInfo findRouteByRid(@RequestParam("rid") Integer rid) {
        return routeService.findRouteByRid(rid);
    }


    /**
     *根据价格范围模糊查询所有路线信息倒序排序
     * 线路排行榜展示功能
     * @param curPage 当前页
     * @param rname 模糊查询路线名
     * @param startPrice 最低价格
     * @param endPrice 最高价格
     * @return
     */
    @RequestMapping("findRoutesFavoriteRank")
    @ResponseBody
    public ResultInfo findRoutesFavoriteRank(@RequestParam(required = false,defaultValue = "1") Integer curPage,
                                             @RequestParam(required = false,value = "rname") String rname,
                                             @RequestParam(required = false,defaultValue = "0") Double startPrice,
                                             @RequestParam(required = false,defaultValue = "0") Double endPrice) {

        return routeService.findRoutesFavoriteRank(curPage,rname,startPrice,endPrice);
    }
}
